﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="kod_meerik", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(KodMeerik))]
    public class KodMeerikSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IKodMeerik clazz;
        
        public KodMeerikSerializer(IKodMeerik clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("dok_tyyp_nm");
            if (clazz.DokTyypNm!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.DokTyypNm))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DokTyypNm");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kaart_nr");
            if (clazz.KaartNr!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KaartNr))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KaartNr");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("omanik_nimi");
            if (clazz.OmanikNimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.OmanikNimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : OmanikNimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kaart_alates");
            if (clazz.KaartAlates!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KaartAlates))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KaartAlates");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kaart_kuni");
            if (clazz.KaartKuni!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KaartKuni))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KaartKuni");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("kaart_olek");
            if (clazz.KaartOlek!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KaartOlek))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : KaartOlek");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "dok_tyyp_nm")) {
                goto dok_tyyp_nm;
            }
            else {
                if ((Reader.LocalName == "kaart_nr")) {
                    goto kaart_nr;
                }
                else {
                    if ((Reader.LocalName == "omanik_nimi")) {
                        goto omanik_nimi;
                    }
                    else {
                        if ((Reader.LocalName == "kaart_alates")) {
                            goto kaart_alates;
                        }
                        else {
                            if ((Reader.LocalName == "kaart_kuni")) {
                                goto kaart_kuni;
                            }
                            else {
                                if ((Reader.LocalName == "kaart_olek")) {
                                    goto kaart_olek;
                                }
                                else {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        dok_tyyp_nm:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kod_meerik>dok_tyyp_nm");
            }
            clazz.DokTyypNm = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("dok_tyyp_nm")).Value;
            goto START;
        kaart_nr:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kod_meerik>kaart_nr");
            }
            clazz.KaartNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kaart_nr")).Value;
            goto START;
        omanik_nimi:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kod_meerik>omanik_nimi");
            }
            clazz.OmanikNimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("omanik_nimi")).Value;
            goto START;
        kaart_alates:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kod_meerik>kaart_alates");
            }
            clazz.KaartAlates = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kaart_alates")).Value;
            goto START;
        kaart_kuni:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kod_meerik>kaart_kuni");
            }
            clazz.KaartKuni = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kaart_kuni")).Value;
            goto START;
        kaart_olek:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>kod_meerik>kaart_olek");
            }
            clazz.KaartOlek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kaart_olek")).Value;
            goto START;
        }
    }
}
